package com.asking.mq;

import com.asking.domain.History;
import org.apache.activemq.command.ActiveMQMapMessage;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.jms.Queue;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class HistoryProducer {
    @Resource
    private JmsMessagingTemplate jmsMessagingTemplate;
    @Resource
    private Queue queue;
    public   void   addHistory(History  history){
       try{
           Date date=new Date();
           DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
           String format = dateFormat.format(date);
           ActiveMQMapMessage message = new ActiveMQMapMessage();
           message.setString("uid",history.getUid()+"");
           message.setString("qid",history.getQid()+"");
           message.setString("score",history.getScore()+"");
           message.setString("cid",history.getCid()+"");
           message.setString("historyTime",format);
           jmsMessagingTemplate.convertAndSend(queue,message);
       }catch (Exception  e){
           e.printStackTrace();
       }

    }
}
